const express = require('express')
const GetApi=require('./GetApi')
const fs=require('fs')
// 创建路由容器
const router = express.Router()
const sql1='select * from new_table'
const sql2='select * from list'
const sql3='select * from comment'
router.get("/",function(req, res){
    const result=GetApi.GetArticle(sql1)
    result.then((FinallyResult)=>{
        res.send(FinallyResult);
    })
})
router.get("/List",function(req, res){
    const result=GetApi.GetArticle(sql2)
    result.then((FinallyResult)=>{
        res.send(FinallyResult);
    })
})
router.get("/MessageBoard",function(req, res){
    const result=GetApi.GetArticle(sql3)
    result.then((FinallyResult)=>{
        res.send(FinallyResult);
    })
})
router.get('/Photo',function (req, res) {
    res.writeHead(200, "Ok");
    let fileList=[]
    function readFileList(path) {
        let files = fs.readdirSync(path);
        files.forEach(function (itm, index) {
           // console.log(path +"/"+itm)
            let content = fs.readFileSync(path +"/"+itm,"binary");
            res.write(content,"binary"); //格式必须为 binary，否则会出错

        })
    }
    readFileList('./Photo/picture',fileList)
    res.end();
})
router.post("/postCom",function(req, res){
    console.log(req.body)
})
module.exports = router
